<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title></title>
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}">
    <link rel="stylesheet" th:href="@{/css/scroll.css}">
    <style>
        /* table 样式 */
        table {
            border-top: 1px solid #ccc;
            border-left: 1px solid #ccc;
        }

        table td,
        table th {
            border-bottom: 1px solid #ccc;
            border-right: 1px solid #ccc;
            padding: 3px 5px;
        }

        table th {
            border-bottom: 2px solid #ccc;
            text-align: center;
        }

        /* blockquote 样式 */
        blockquote {
            display: block;
            border-left: 8px solid #d0e5f2;
            padding: 5px 10px;
            margin: 10px 0;
            line-height: 1.4;
            font-size: 100%;
            background-color: #f1f1f1;
        }

        /* code 样式 */
        code {
            display: inline-block;
            *display: inline;
            *zoom: 1;
            background-color: #f1f1f1;
            border-radius: 3px;
            padding: 3px 5px;
            margin: 0 3px;
        }

        pre code {
            display: block;
        }

        /* ul ol 样式 */
        ul, ol {
            margin: 10px 0 10px 20px;
        }
    </style>
</head>
<body>
<div class="layui-fluid">
    <nav style="margin: 10px 0; padding-bottom:5px;border-bottom: 1px dashed darkgray;">
    <span class="layui-breadcrumb">
        <a th:href="@{/admin/home}">首页</a>
        <a>系统管理</a>
        <a>
            <cite>通知管理</cite>
        </a>
    </span>
    </nav>
    <div>
        <div class="layui-form-item">
            <label class="layui-form-label">请输入标题</label>
            <div class="layui-input-block">
                <input type="text" id="title" name="title" placeholder="请输入标题" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div id="wrap"></div>
        <div style="margin-top: 30px;">

            <button class="layui-btn layui-btn-normal" onclick="openDb()">
                <i class="layui-icon">&#xe60d;</i>
                图床
            </button>

            <button class="layui-btn layui-btn-warm" onclick="showHtml()">
                <i class="layui-icon">&#xe660;</i>
                预览
            </button>
            <button class="layui-btn layui-btn-normal" onclick="getHtml()">
                <i class="layui-icon">&#xe609;</i>
                立即发布
            </button>
        </div>
    </div>
</div>
<script th:src="@{/js/wangeditor.js}"></script>
<script th:src="@{/js/jquery-3.4.1.js}"></script>
<script th:src="@{/layui/layui.js}"></script>
<script th:src="@{/layui/lay/modules/element.js}"></script>
<script th:src="@{/layui/lay/modules/table.js}"></script>

<script type="text/javascript">
    var E = window.wangEditor
    var editor = new E("#wrap")
    editor.create()


    function showHtml() {
        var html = editor.txt.html();

        //页面层-自定义

        layer.open({
            type: 1,
            title: "预览",
            closeBtn: 1,
            maxmin: true, //开启最大化最小化按钮
            area: ['893px', '550px'],
            shadeClose: true,
            skin: 'yourclass',
            content: html
        });
    }


    function getHtml() {
        var title = $("#title").val();
        var content = editor.txt.html();
        if (title == "" || content === "<p><br></p>") {
            layer.msg("请输入标题及内容", function () {

            });
            return false;
        }
        console.log("标题：" + title);
        console.log("内容：" + content);
        $.post("advice/add", {
            title, content
        }, function (resp) {
            console.log(resp)
            if(resp.code==0){
                layer.msg('已发布', {icon: 1});
            }else if(resp.code ==500){
                layer.msg('发布失败:'+resp.msg, {icon: 5});
            }
        })

    }


    function openDb() {
        //iframe层

        layer.open({
            type: 2,
            title: '星时代在线图床',
            shadeClose: true,
            shade: 0.8,
            area: ['80%', '90%'],
            content: '../office/drawBed/' //iframe的url
        });
    }
</script>
</body>
</html>